
;This is the code that writes the tables in the binary format
;according to the rules of the SLUG code ($SLUG_DIR/data). 
;

pro write_slug_table, all=all

if keyword_set(all) then begin
spawn, 'ls $SLUG_DIR/data/', ls_dirs


for i=0, n_elements(ls_dirs)-1 do begin
spawn, 'ls $SLUG_DIR/data/'+ls_dirs[i], ls_subdirs   
   for j=0, n_elements(ls_subdirs)-1 do begin

      cd, '$SLUG_DIR/data/'+ls_dirs[i]+'/'+ls_subdirs[j]+'/'
      write_slug_table
      print, '$SLUG_DIR/data/'+ls_dirs[i]+'/'+ls_subdirs[j]+'/'
   endfor
endfor
endif else begin

what=['bol','fuv','nuv','qh0',$
'J', 'H', 'K', 'SDSSu', 'SDSSg',$ 
 'SDSSr', 'SDSSi', 'SDSSz',$ 
 'johnsonU', 'johnsonB',$ 
 'johnsonV', 'johnsonR',$ 
 'johnsonI']

for i=0, n_elements(what)-1 do begin
;read
    table=double(mrdfits('log_'+what[i]+'_table.fits'))
    one_colum=reform(table,n_elements(table))
    openw, 1, 'log_'+what[i]+'_table.dat' 
    writeu, 1, one_colum
    close, 1 
endfor

what=['times_for_tables.fits','star_cut.fits','mass_for_tables.fits',$
      'lowmass_masses.fits','lowmass_log_qh0.fits','lowmass_log_nuv.fits',$
      'lowmass_log_fuv.fits','lowmass_log_bol.fits',$
'lowmass_log_J.fits', 'lowmass_log_H.fits',$ 
 'lowmass_log_K.fits', 'lowmass_log_SDSSu.fits',$ 
 'lowmass_log_SDSSg.fits', 'lowmass_log_SDSSr.fits',$ 
 'lowmass_log_SDSSi.fits', 'lowmass_log_SDSSz.fits',$ 
 'lowmass_log_johnsonU.fits', 'lowmass_log_johnsonB.fits',$ 
 'lowmass_log_johnsonV.fits', 'lowmass_log_johnsonR.fits',$ 
 'lowmass_log_johnsonI.fits']

for i=0, n_elements(what)-1 do begin
;read
    table=double(mrdfits(what[i]))
    openw, 1, (strsplit(what[i], '.', /extract))[0]+'.dat' 
    writeu, 1, table
    close, 1 

endfor


endelse
end
